package com.liran.controller;


import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liran.entity.ConsumeInfoEntity;
import com.liran.param.ConsumeInfoListParam;
import com.liran.service.ConsumeInfoService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author whh
 * @since 2022-07-11
 */
@RestController
@RequestMapping("/sys/consume")
@AllArgsConstructor
public class ConsumeInfoController {

    private final ConsumeInfoService consumeInfoService;

    @PostMapping("/list")
    public Page<ConsumeInfoEntity> list(@RequestBody ConsumeInfoListParam consumeInfoListParam) {
        return consumeInfoService.listSearch(consumeInfoListParam);
    }

    @PostMapping("/operate")
    public Boolean operate(@RequestBody ConsumeInfoEntity consumeInfoEntity) {
        //防止意外赋值
        if (consumeInfoEntity.getIsVip() == 2) {
            consumeInfoEntity.setVipId(null);
        } else if (consumeInfoEntity.getIsVip() == 1) {
            consumeInfoEntity.setName(null);
        }
        consumeInfoEntity.setGmtCreate(LocalDateTimeUtil.now());
        return consumeInfoService.saveOrUpdate(consumeInfoEntity);
    }

    @GetMapping("/del/{id}")
    public Boolean del(@PathVariable Long id) {
        return consumeInfoService.removeById(id);
    }
}

